package com.example.appkcsj.slice;

import com.example.appkcsj.ResourceTable;
import com.example.appkcsj.dbutils.DBUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.TextField;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.aafwk.content.Operation;

public class mdeleteAbilitySlice extends AbilitySlice {
    private final static HiLogLabel HI_LOG_LABEL=
            new HiLogLabel(HiLog.LOG_APP,0x00201,"mdeleteAbilitySlice");
    private TextField t,t1;
    private Button b;
    private DBUtils dbUtils;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_mdelete);
        b = (Button) findComponentById(ResourceTable.Id_butm2);
        t = (TextField) findComponentById(ResourceTable.Id_fieldm2);
        t1 = (TextField) findComponentById(ResourceTable.Id_textFieldm1);
        dbUtils=new DBUtils(mdeleteAbilitySlice.this);
        b.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                boolean flag=dbUtils.deleteStudent(t.getText());
                if(flag){
                    HiLog.info(HI_LOG_LABEL,"删除数据："+flag);
                    Intent m = new Intent();
                    present(new MainAbilitySlice(),m);
                    Operation operation = new Intent.OperationBuilder()
                            .withDeviceId("")
                            .withBundleName("com.example.appkcsj")//跳转到哪个应用
                            .withAbilityName("com.example.appkcsj.mdeleteAbility")//要跳转的包名
                            .build();//将上面的信息打包
                    m.setOperation(operation);
                    startAbility(m);
                }
                else{
                    HiLog.info(HI_LOG_LABEL,"删除数据："+flag);
                }
            }
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
